home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / sox.zip / ST.H < prev    next >
C/C++ Source or Header  |  1992-06-15  |  5KB  |  178 lines

  1. /*
  2.  * July 5, 1991
  3.  * Copyright 1991 Lance Norskog And Sundry Contributors
  4.  * This source code is freely redistributable and may be used for
  5.  * any purpose.  This copyright notice must be maintained. 
  6.  * Lance Norskog And Sundry Contributors are not responsible for 
  7.  * the consequences of using this software.
  8.  */
  9.  
  10. /*
  11.  * Sound Tools sources header file.
  12.  */
  13.  
  14. #include <stdio.h>
  15.  
  16. /*
  17.  * Handler structure for each format.
  18.  */
  19.  
  20. typedef struct format {
  21.     char    **names;    /* file type names */
  22.     int    (*startread)();            
  23.     int    (*read)();            
  24.     int    (*stopread)();        
  25.     int    (*startwrite)();            
  26.     int    (*write)();
  27.     int    (*stopwrite)();        
  28. } format_t;
  29.  
  30. extern format_t formats[];
  31.  
  32. /* Signal parameters */
  33.  
  34. struct  signalinfo {
  35.     int    rate;            /* sampling rate */
  36.     int    size;            /* word length of data */
  37.     int    style;            /* format of sample numbers */
  38.     int    channels;        /* number of sound channels */
  39. };
  40.  
  41. /* Pipe parameters */
  42.  
  43. struct    pipeinfo {
  44.     FILE    *pout;            /* Output file */
  45.     FILE    *pin;            /* Input file */
  46. };
  47.  
  48. /*
  49.  *  Format information for input and output files.
  50.  */
  51.  
  52. #define    PRIVSIZE    50
  53.  
  54. struct soundstream {
  55.     struct    signalinfo info;    /* signal specifications */
  56.     char    swap;            /* do byte- or word-swap */
  57.     char    seekable;        /* can seek on this file */
  58.     char    *filename;        /* file name */
  59.     char    *filetype;        /* type of file */
  60.     FILE    *fp;            /* File stream pointer */
  61.     format_t *h;            /* format struct for this file */
  62.     char    priv[PRIVSIZE];        /* format's private data area */
  63. };
  64.  
  65. extern struct soundstream informat, outformat;
  66. typedef struct soundstream *ft_t;
  67.  
  68. /* Size field */
  69. #define    BYTE    1
  70. #define    WORD    2
  71. #define    LONG    4
  72. #define    FLOAT    5
  73. #define DOUBLE    6
  74. #define IEEE    7        /* IEEE 80-bit floats.  Is it necessary? */
  75.  
  76. /* Style field */
  77. #define UNSIGNED    1    /* unsigned linear: Sound Blaster */
  78. #define SIGN2        2    /* signed linear 2's comp: Mac */
  79. #define    ULAW        3    /* U-law signed logs: US telephony, SPARC */
  80. #define ALAW        4    /* A-law signed logs: non-US telephony */
  81.  
  82. extern char *sizes[], *styles[];
  83.  
  84. /*
  85.  * Handler structure for each effect.
  86.  */
  87.  
  88. typedef struct {
  89.     char    *name;            /* effect name */
  90.     int    flags;            /* this and that */
  91.     int    (*getopts)();        /* process arguments */
  92.     int    (*start)();        /* start off effect */
  93.     int    (*flow)();        /* do a buffer */
  94.     int    (*drain)();        /* drain out at end */
  95.     int    (*stop)();        /* finish up effect */
  96. } effect_t;
  97.  
  98. extern effect_t effects[];
  99.  
  100. #define    EFF_CHAN    1        /* Effect can mix channels up/down */
  101. #define EFF_RATE    2        /* Effect can alter data rate */
  102. #define EFF_MCHAN    4        /* Effect can handle multi-channel */
  103.  
  104. struct effect {
  105.     char        *name;        /* effect name */
  106.     struct signalinfo ininfo;    /* input signal specifications */
  107.     struct signalinfo outinfo;    /* output signal specifications */
  108.     effect_t     *h;        /* effects driver */
  109.     char        priv[PRIVSIZE];    /* private area for effect */
  110. };
  111.  
  112. typedef struct effect *eff_t;
  113.  
  114. #ifdef    __STDC__
  115. #define    P1(x) x
  116. #define    P2(x,y) x, y
  117. #define    P3(x,y,z) x, y, z
  118. #define    P4(x,y,z,w) x, y, z, w
  119. #else
  120. #define P1(x)
  121. #define P2(x,y)
  122. #define P3(x,y,z)
  123. #define P4(x,y,z,w)
  124. #endif
  125.  
  126. /* Utilities to read and write shorts and longs little-endian and big-endian */
  127. unsigned short rlshort(P1(ft_t ft));            /* short little-end */
  128. unsigned short rbshort(P1(ft_t ft));            /* short big-end    */
  129. unsigned short wlshort(P2(ft_t ft, unsigned int us));    /* short little-end */
  130. unsigned short wbshort(P2(ft_t ft, unsigned int us));    /* short big-end    */
  131. unsigned long  rllong(P1(ft_t ft));            /* long little-end  */
  132. unsigned long  rblong(P1(ft_t ft));            /* long big-end     */
  133. unsigned long  wllong(P2(ft_t ft, unsigned long ul));    /* long little-end  */
  134. unsigned long  wblong(P2(ft_t ft, unsigned long ul));    /* long big-end     */
  135. /* Read and write words and longs in "machine format".  Swap if indicated.  */
  136. unsigned short rshort(P1(ft_t ft));            
  137. unsigned short wshort(P2(ft_t ft, unsigned int us));
  138. unsigned long  rlong(P1(ft_t ft));        
  139. unsigned long  wlong(P2(ft_t ft, unsigned long ul));
  140. /* Utilities to byte-swap values */
  141. unsigned short swapw(P1(unsigned int us));        /* Swap short */
  142. unsigned long  swapl(P1(unsigned long ul));        /* Swap long */
  143.  
  144. #ifdef    SYSV
  145. #define    bcopy(from, to, len)    memcpy(to, from, len)
  146. #define    index        strchr
  147. #define    rindex        strrchr
  148. #endif
  149.  
  150. typedef    unsigned int u_i;
  151. typedef    unsigned long u_l;
  152. typedef    unsigned short u_s;
  153.  
  154. #define    MAXRATE    50*1024            /* maximum sample rate */
  155.  
  156. #ifdef    unix
  157. /* Some wacky processors don't have arithmetic down shift, so do divs */
  158. #define LEFT(datum, bits)    (datum << bits)
  159. /* Most compilers will turn this into a shift if they can, don't worry */
  160. #define RIGHT(datum, bits)    (datum / (1L << bits))
  161. #else
  162. /* x86 & 68k PC's have arith shift ops and dumb compilers */
  163. #define LEFT(datum, bits)    (datum << bits)
  164. #define RIGHT(datum, bits)    (datum >> bits)
  165. #endif
  166.  
  167. #ifndef    M_PI
  168. #define M_PI    3.14159265358979323846
  169. #endif
  170.  
  171. #ifdef    unix
  172. #define READBINARY    "r"
  173. #define WRITEBINARY    "w"
  174. #else
  175. #define READBINARY    "rb"
  176. #define WRITEBINARY    "wb"
  177. #endif
  178.